package per.dg.digital_klotski.views.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import per.dg.digital_klotski.MainActivity;
import per.dg.digital_klotski.R;
import per.dg.digital_klotski.utils.FontDisplayUtil;
import per.dg.digital_klotski.utils.SharedPreferencesManager;
import per.dg.digital_klotski.views.App;
import per.dg.digital_klotski.views.base.BaseActivity;

public class HomeActivity extends BaseActivity {

    ImageView img3, img4, img5, img6, img7, img8, imgSound, imgMusic, imgClose;

    View.OnClickListener onClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ((App)getApplication()).starttip();
            Intent intent = new Intent(HomeActivity.this, MainActivity.class);
            switch (v.getId()){
                case R.id.img_3:
                    intent.putExtra("space", 3);
                    startActivity(intent);
                    break;
                case R.id.img_4:
                    intent.putExtra("space", 4);
                    startActivity(intent);
                    break;
                case R.id.img_5:
                    intent.putExtra("space", 5);
                    startActivity(intent);
                    break;
                case R.id.img_6:
                    intent.putExtra("space", 6);
                    startActivity(intent);
                    break;
                case R.id.img_7:
                    intent.putExtra("space", 7);
                    startActivity(intent);
                    break;
                case R.id.img_8:
                    intent.putExtra("space", 8);
                    startActivity(intent);
                    break;
                case R.id.img_sound:
                    soundClick();
                    break;
                case R.id.img_music:
                    musicClick();
                    break;
                case R.id.img_exit:
                    finish();
                    break;
            }
        }
    };

    private void startActivity(int space){

    }

    private void musicClick(){
        sharedPreferencesManager.saveMusic(!sharedPreferencesManager.getMusic());
        setMusicData();
        ((App)getApplication()).startBgm();
    }

    private void soundClick(){
        sharedPreferencesManager.saveSound(!sharedPreferencesManager.getSound());
        setSoundData();
    }

    SharedPreferencesManager sharedPreferencesManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);

        initView();


    }

    @Override
    protected void onResume() {
        super.onResume();
        initData();
    }

    private void initData() {
        sharedPreferencesManager = SharedPreferencesManager.getInstance(this);
        setSoundData();
        setMusicData();
    }

    private void setSoundData() {
        imgSound.setImageDrawable(getResources().getDrawable(sharedPreferencesManager.getSound()? R.mipmap.btn_sound_on_normal : R.mipmap.btn_sound_off_normal));
    }

    private void setMusicData() {
        imgMusic.setImageDrawable(getResources().getDrawable(sharedPreferencesManager.getMusic()? R.mipmap.btn_music_on_normal : R.mipmap.btn_music_off_normal));
    }

    private void initView() {
        ViewGroup contentView =  findViewById(android.R.id.content);
        img3 = findViewById(R.id.img_3);
        img3.setOnClickListener(onClickListener);
        img4 = findViewById(R.id.img_4);
        img4.setOnClickListener(onClickListener);
        img5 = findViewById(R.id.img_5);
        img5.setOnClickListener(onClickListener);
        img6 = findViewById(R.id.img_6);
        img6.setOnClickListener(onClickListener);
        img7 = findViewById(R.id.img_7);
        img7.setOnClickListener(onClickListener);
        img8 = findViewById(R.id.img_8);
        img8.setOnClickListener(onClickListener);
        imgSound = findViewById(R.id.img_sound);
        imgSound.setOnClickListener(onClickListener);
        imgMusic = findViewById(R.id.img_music);
        imgMusic.setOnClickListener(onClickListener);
        imgClose = findViewById(R.id.img_exit);
        imgClose.setOnClickListener(onClickListener);
    }
}